home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / lex / Scanner.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  15.8 KB  |  520 lines  |  [TEXT/Moml]

  1. local open Obj Lexing in
  2.  
  3.  
  4. open Fnlib Syntax Grammar Scan_aux;
  5.  
  6. fun action_50 lexbuf = (
  7.  raise Lexical_error
  8.              ("illegal character #" ^ makestring(getLexeme lexbuf)) )
  9. and action_49 lexbuf = (
  10.  raise Lexical_error "unterminated lexer definition" )
  11. and action_48 lexbuf = (
  12.  Tdash )
  13. and action_47 lexbuf = (
  14.  Tcaret )
  15. and action_46 lexbuf = (
  16.  Trparen )
  17. and action_45 lexbuf = (
  18.  Tlparen )
  19. and action_44 lexbuf = (
  20.  Tplus )
  21. and action_43 lexbuf = (
  22.  Tmaybe )
  23. and action_42 lexbuf = (
  24.  Tstar )
  25. and action_41 lexbuf = (
  26.  Trbracket )
  27. and action_40 lexbuf = (
  28.  Tlbracket )
  29. and action_39 lexbuf = (
  30.  Teof )
  31. and action_38 lexbuf = (
  32.  Tunderscore )
  33. and action_37 lexbuf = (
  34.  Tor )
  35. and action_36 lexbuf = (
  36.  Tend )
  37. and action_35 lexbuf = (
  38.  Tequal )
  39. and action_34 lexbuf = (
  40.  let val n1 = getLexemeEnd lexbuf
  41.           val () = brace_depth := 1
  42.           val n2 = action lexbuf
  43.       in Taction(Location(n1, n2)) end )
  44. and action_33 lexbuf = (
  45.  Tchar(char lexbuf) )
  46. and action_32 lexbuf = (
  47.  (reset_string_buffer();
  48.        string lexbuf;
  49.        Tstring(get_stored_string())) )
  50. and action_31 lexbuf = (
  51.  case getLexeme lexbuf of
  52.         "rule" => Trule
  53.       | "parse" => Tparse
  54.       | "and" => Tand
  55.       | "eof" => Teof
  56.       | s => Tident s )
  57. and action_30 lexbuf = (
  58.  raise Lexical_error "unmatched comment bracket" )
  59. and action_29 lexbuf = (
  60.  (comment_depth := 1; comment lexbuf; main lexbuf) )
  61. and action_28 lexbuf = (
  62.  main lexbuf )
  63. and action_27 lexbuf = (
  64.  action lexbuf )
  65. and action_26 lexbuf = (
  66.  raise Lexical_error "unterminated action" )
  67. and action_25 lexbuf = (
  68.  raise Lexical_error "unmatched comment bracket" )
  69. and action_24 lexbuf = (
  70.  (comment_depth := 1; comment lexbuf; action lexbuf) )
  71. and action_23 lexbuf = (
  72.  (reset_string_buffer();
  73.        string lexbuf;
  74.        reset_string_buffer();
  75.        action lexbuf) )
  76. and action_22 lexbuf = (
  77.  (decr brace_depth;
  78.            if !brace_depth = 0 then
  79.              getLexemeStart lexbuf
  80.            else
  81.              action lexbuf) )
  82. and action_21 lexbuf = (
  83.  (incr brace_depth; action lexbuf) )
  84. and action_20 lexbuf = (
  85.  (store_string_char(getLexemeChar lexbuf 0);
  86.        string lexbuf) )
  87. and action_19 lexbuf = (
  88.  raise Lexical_error "invalid character in string" )
  89. and action_18 lexbuf = (
  90.  raise Lexical_error "unterminated string" )
  91. and action_17 lexbuf = (
  92.  raise Lexical_error "ill-formed escape sequence in string" )
  93. and action_16 lexbuf = (
  94.  let val code = char_for_decimal_code lexbuf 1 in
  95.         if Char.ord code >= 256 then
  96.           raise Lexical_error "character code in string > 255"
  97.         else ();
  98.         store_string_char code;
  99.         string lexbuf
  100.       end )
  101. and action_15 lexbuf = (
  102.  (store_string_char(
  103.            Char.chr(Char.ord(getLexemeChar lexbuf 2) - 64));
  104.          string lexbuf) )
  105. and action_14 lexbuf = (
  106.  (store_string_char(char_for_backslash(getLexemeChar lexbuf 1));
  107.        string lexbuf) )
  108. and action_13 lexbuf = (
  109.  string lexbuf )
  110. and action_12 lexbuf = (
  111.  () )
  112. and action_11 lexbuf = (
  113.  raise Lexical_error "ill-formed character constant" )
  114. and action_10 lexbuf = (
  115.  getLexemeChar lexbuf 0 )
  116. and action_9 lexbuf = (
  117.  raise Lexical_error "invalid character in character constant" )
  118. and action_8 lexbuf = (
  119.  raise Lexical_error "unterminated character constant" )
  120. and action_7 lexbuf = (
  121.  raise Lexical_error "ill-formed escape sequence in character constant" )
  122. and action_6 lexbuf = (
  123.  let val code = char_for_decimal_code lexbuf 1 in
  124.         if Char.ord code >= 256 then
  125.           raise Lexical_error "character code in string > 255"
  126.         else ();
  127.         code
  128.       end )
  129. and action_5 lexbuf = (
  130.  Char.chr(Char.ord(getLexemeChar lexbuf 2) - 64) )
  131. and action_4 lexbuf = (
  132.  char_for_backslash (getLexemeChar lexbuf 1) )
  133. and action_3 lexbuf = (
  134.  comment lexbuf )
  135. and action_2 lexbuf = (
  136.  raise Lexical_error "unterminated comment" )
  137. and action_1 lexbuf = (
  138.  (decr comment_depth;
  139.        if !comment_depth = 0 then () else comment lexbuf) )
  140. and action_0 lexbuf = (
  141.  (incr comment_depth; comment lexbuf) )
  142. and state_0 lexbuf = (
  143.  let val currChar = getNextChar lexbuf in
  144.  case currChar of
  145.     #"*" => state_77 lexbuf
  146.  |  #"(" => state_76 lexbuf
  147.  |  #"\^Z" => action_2 lexbuf
  148.  |  #"\^@" => action_2 lexbuf
  149.  |  _ => action_3 lexbuf
  150.  end)
  151. and state_1 lexbuf = (
  152.  let val currChar = getNextChar lexbuf in
  153.  if currChar >= #"\^A" andalso currChar <= #"\^Y" then  state_58 lexbuf
  154.  else case currChar of
  155.     #"\^_" => state_58 lexbuf
  156.  |  #"\^^" => state_58 lexbuf
  157.  |  #"\^]" => state_58 lexbuf
  158.  |  #"\^\" => state_58 lexbuf
  159.  |  #"\^[" => state_58 lexbuf
  160.  |  #"\127" => state_58 lexbuf
  161.  |  #"\255" => state_58 lexbuf
  162.  |  #"\\" => state_61 lexbuf
  163.  |  #"\^Z" => state_59 lexbuf
  164.  |  #"\^@" => action_8 lexbuf
  165.  |  _ => state_60 lexbuf
  166.  end)
  167. and state_2 lexbuf = (
  168.  let val currChar = getNextChar lexbuf in
  169.  if currChar >= #"\^A" andalso currChar <= #"\^Y" then  action_19 lexbuf
  170.  else case currChar of
  171.     #"\^_" => action_19 lexbuf
  172.  |  #"\^^" => action_19 lexbuf
  173.  |  #"\^]" => action_19 lexbuf
  174.  |  #"\^\" => action_19 lexbuf
  175.  |  #"\^[" => action_19 lexbuf
  176.  |  #"\127" => action_19 lexbuf
  177.  |  #"\255" => action_19 lexbuf
  178.  |  #"\\" => state_48 lexbuf
  179.  |  #"\"" => action_12 lexbuf
  180.  |  #"\^Z" => action_18 lexbuf
  181.  |  #"\^@" => action_18 lexbuf
  182.  |  _ => action_20 lexbuf
  183.  end)
  184. and state_3 lexbuf = (
  185.  let val currChar = getNextChar lexbuf in
  186.  case currChar of
  187.     #"}" => action_22 lexbuf
  188.  |  #"{" => action_21 lexbuf
  189.  |  #"*" => state_38 lexbuf
  190.  |  #"(" => state_37 lexbuf
  191.  |  #"\"" => action_23 lexbuf
  192.  |  #"\^Z" => action_26 lexbuf
  193.  |  #"\^@" => action_26 lexbuf
  194.  |  _ => action_27 lexbuf
  195.  end)
  196. and state_4 lexbuf = (
  197.  let val currChar = getNextChar lexbuf in
  198.  if currChar >= #"A" andalso currChar <= #"Z" then  state_18 lexbuf
  199.  else if currChar >= #"f" andalso currChar <= #"z" then  state_18 lexbuf
  200.  else case currChar of
  201.     #"d" => state_18 lexbuf
  202.  |  #"c" => state_18 lexbuf
  203.  |  #"b" => state_18 lexbuf
  204.  |  #"a" => state_18 lexbuf
  205.  |  #"\r" => state_7 lexbuf
  206.  |  #"\t" => state_7 lexbuf
  207.  |  #"\n" => state_7 lexbuf
  208.  |  #" " => state_7 lexbuf
  209.  |  #"|" => action_37 lexbuf
  210.  |  #"{" => action_34 lexbuf
  211.  |  #"e" => state_24 lexbuf
  212.  |  #"`" => action_33 lexbuf
  213.  |  #"_" => action_38 lexbuf
  214.  |  #"^" => action_47 lexbuf
  215.  |  #"]" => action_41 lexbuf
  216.  |  #"[" => action_40 lexbuf
  217.  |  #"?" => action_43 lexbuf
  218.  |  #"=" => action_35 lexbuf
  219.  |  #";" => action_36 lexbuf
  220.  |  #"-" => action_48 lexbuf
  221.  |  #"+" => action_44 lexbuf
  222.  |  #"*" => state_12 lexbuf
  223.  |  #")" => action_46 lexbuf
  224.  |  #"(" => state_10 lexbuf
  225.  |  #"\"" => action_32 lexbuf
  226.  |  #"\^Z" => action_49 lexbuf
  227.  |  #"\^@" => action_49 lexbuf
  228.  |  _ => action_50 lexbuf
  229.  end)
  230. and state_7 lexbuf = (
  231.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  232.  setLexLastAction lexbuf (magic action_28);
  233.  let val currChar = getNextChar lexbuf in
  234.  case currChar of
  235.     #"\r" => state_32 lexbuf
  236.  |  #"\t" => state_32 lexbuf
  237.  |  #"\n" => state_32 lexbuf
  238.  |  #" " => state_32 lexbuf
  239.  |  _ => backtrack lexbuf
  240.  end)
  241. and state_10 lexbuf = (
  242.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  243.  setLexLastAction lexbuf (magic action_45);
  244.  let val currChar = getNextChar lexbuf in
  245.  case currChar of
  246.     #"*" => action_29 lexbuf
  247.  |  _ => backtrack lexbuf
  248.  end)
  249. and state_12 lexbuf = (
  250.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  251.  setLexLastAction lexbuf (magic action_42);
  252.  let val currChar = getNextChar lexbuf in
  253.  case currChar of
  254.     #")" => action_30 lexbuf
  255.  |  _ => backtrack lexbuf
  256.  end)
  257. and state_18 lexbuf = (
  258.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  259.  setLexLastAction lexbuf (magic action_31);
  260.  let val currChar = getNextChar lexbuf in
  261.  if currChar >= #"0" andalso currChar <= #"9" then  state_27 lexbuf
  262.  else if currChar >= #"A" andalso currChar <= #"Z" then  state_27 lexbuf
  263.  else if currChar >= #"a" andalso currChar <= #"z" then  state_27 lexbuf
  264.  else case currChar of
  265.     #"'" => state_27 lexbuf
  266.  |  #"_" => state_27 lexbuf
  267.  |  _ => backtrack lexbuf
  268.  end)
  269. and state_24 lexbuf = (
  270.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  271.  setLexLastAction lexbuf (magic action_31);
  272.  let val currChar = getNextChar lexbuf in
  273.  if currChar >= #"0" andalso currChar <= #"9" then  state_27 lexbuf
  274.  else if currChar >= #"A" andalso currChar <= #"Z" then  state_27 lexbuf
  275.  else if currChar >= #"a" andalso currChar <= #"n" then  state_27 lexbuf
  276.  else if currChar >= #"p" andalso currChar <= #"z" then  state_27 lexbuf
  277.  else case currChar of
  278.     #"'" => state_27 lexbuf
  279.  |  #"_" => state_27 lexbuf
  280.  |  #"o" => state_28 lexbuf
  281.  |  _ => backtrack lexbuf
  282.  end)
  283. and state_27 lexbuf = (
  284.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  285.  setLexLastAction lexbuf (magic action_31);
  286.  let val currChar = getNextChar lexbuf in
  287.  if currChar >= #"0" andalso currChar <= #"9" then  state_27 lexbuf
  288.  else if currChar >= #"A" andalso currChar <= #"Z" then  state_27 lexbuf
  289.  else if currChar >= #"a" andalso currChar <= #"z" then  state_27 lexbuf
  290.  else case currChar of
  291.     #"'" => state_27 lexbuf
  292.  |  #"_" => state_27 lexbuf
  293.  |  _ => backtrack lexbuf
  294.  end)
  295. and state_28 lexbuf = (
  296.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  297.  setLexLastAction lexbuf (magic action_31);
  298.  let val currChar = getNextChar lexbuf in
  299.  if currChar >= #"0" andalso currChar <= #"9" then  state_27 lexbuf
  300.  else if currChar >= #"A" andalso currChar <= #"Z" then  state_27 lexbuf
  301.  else if currChar >= #"g" andalso currChar <= #"z" then  state_27 lexbuf
  302.  else case currChar of
  303.     #"'" => state_27 lexbuf
  304.  |  #"_" => state_27 lexbuf
  305.  |  #"e" => state_27 lexbuf
  306.  |  #"d" => state_27 lexbuf
  307.  |  #"c" => state_27 lexbuf
  308.  |  #"b" => state_27 lexbuf
  309.  |  #"a" => state_27 lexbuf
  310.  |  #"f" => state_29 lexbuf
  311.  |  _ => backtrack lexbuf
  312.  end)
  313. and state_29 lexbuf = (
  314.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  315.  setLexLastAction lexbuf (magic action_31);
  316.  let val currChar = getNextChar lexbuf in
  317.  if currChar >= #"0" andalso currChar <= #"9" then  state_27 lexbuf
  318.  else if currChar >= #"A" andalso currChar <= #"Z" then  state_27 lexbuf
  319.  else if currChar >= #"a" andalso currChar <= #"z" then  state_27 lexbuf
  320.  else case currChar of
  321.     #"'" => state_27 lexbuf
  322.  |  #"_" => state_27 lexbuf
  323.  |  _ => backtrack lexbuf
  324.  end)
  325. and state_32 lexbuf = (
  326.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  327.  setLexLastAction lexbuf (magic action_28);
  328.  let val currChar = getNextChar lexbuf in
  329.  case currChar of
  330.     #"\r" => state_32 lexbuf
  331.  |  #"\t" => state_32 lexbuf
  332.  |  #"\n" => state_32 lexbuf
  333.  |  #" " => state_32 lexbuf
  334.  |  _ => backtrack lexbuf
  335.  end)
  336. and state_37 lexbuf = (
  337.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  338.  setLexLastAction lexbuf (magic action_27);
  339.  let val currChar = getNextChar lexbuf in
  340.  case currChar of
  341.     #"*" => action_24 lexbuf
  342.  |  _ => backtrack lexbuf
  343.  end)
  344. and state_38 lexbuf = (
  345.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  346.  setLexLastAction lexbuf (magic action_27);
  347.  let val currChar = getNextChar lexbuf in
  348.  case currChar of
  349.     #")" => action_25 lexbuf
  350.  |  _ => backtrack lexbuf
  351.  end)
  352. and state_48 lexbuf = (
  353.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  354.  setLexLastAction lexbuf (magic action_17);
  355.  let val currChar = getNextChar lexbuf in
  356.  if currChar >= #"0" andalso currChar <= #"9" then  state_51 lexbuf
  357.  else case currChar of
  358.     #"\"" => action_14 lexbuf
  359.  |  #"\\" => action_14 lexbuf
  360.  |  #"b" => action_14 lexbuf
  361.  |  #"n" => action_14 lexbuf
  362.  |  #"r" => action_14 lexbuf
  363.  |  #"t" => action_14 lexbuf
  364.  |  #"\r" => state_49 lexbuf
  365.  |  #"\t" => state_49 lexbuf
  366.  |  #"\n" => state_49 lexbuf
  367.  |  #" " => state_49 lexbuf
  368.  |  #"^" => state_52 lexbuf
  369.  |  _ => backtrack lexbuf
  370.  end)
  371. and state_49 lexbuf = (
  372.  let val currChar = getNextChar lexbuf in
  373.  case currChar of
  374.     #"\r" => state_49 lexbuf
  375.  |  #"\t" => state_49 lexbuf
  376.  |  #"\n" => state_49 lexbuf
  377.  |  #" " => state_49 lexbuf
  378.  |  #"\\" => action_13 lexbuf
  379.  |  _ => backtrack lexbuf
  380.  end)
  381. and state_51 lexbuf = (
  382.  let val currChar = getNextChar lexbuf in
  383.  if currChar >= #"0" andalso currChar <= #"9" then  state_54 lexbuf
  384.  else backtrack lexbuf
  385.  end)
  386. and state_52 lexbuf = (
  387.  let val currChar = getNextChar lexbuf in
  388.  if currChar >= #"@" andalso currChar <= #"_" then  action_15 lexbuf
  389.  else backtrack lexbuf
  390.  end)
  391. and state_54 lexbuf = (
  392.  let val currChar = getNextChar lexbuf in
  393.  if currChar >= #"0" andalso currChar <= #"9" then  action_16 lexbuf
  394.  else backtrack lexbuf
  395.  end)
  396. and state_58 lexbuf = (
  397.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  398.  setLexLastAction lexbuf (magic action_9);
  399.  let val currChar = getNextChar lexbuf in
  400.  case currChar of
  401.     #"`" => action_10 lexbuf
  402.  |  _ => backtrack lexbuf
  403.  end)
  404. and state_59 lexbuf = (
  405.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  406.  setLexLastAction lexbuf (magic action_8);
  407.  let val currChar = getNextChar lexbuf in
  408.  case currChar of
  409.     #"`" => action_10 lexbuf
  410.  |  _ => backtrack lexbuf
  411.  end)
  412. and state_60 lexbuf = (
  413.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  414.  setLexLastAction lexbuf (magic action_11);
  415.  let val currChar = getNextChar lexbuf in
  416.  case currChar of
  417.     #"`" => action_10 lexbuf
  418.  |  _ => backtrack lexbuf
  419.  end)
  420. and state_61 lexbuf = (
  421.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  422.  setLexLastAction lexbuf (magic action_7);
  423.  let val currChar = getNextChar lexbuf in
  424.  if currChar >= #"0" andalso currChar <= #"9" then  state_62 lexbuf
  425.  else case currChar of
  426.     #"\\" => state_63 lexbuf
  427.  |  #"b" => state_63 lexbuf
  428.  |  #"n" => state_63 lexbuf
  429.  |  #"r" => state_63 lexbuf
  430.  |  #"t" => state_63 lexbuf
  431.  |  #"`" => state_65 lexbuf
  432.  |  #"^" => state_64 lexbuf
  433.  |  _ => backtrack lexbuf
  434.  end)
  435. and state_62 lexbuf = (
  436.  let val currChar = getNextChar lexbuf in
  437.  if currChar >= #"0" andalso currChar <= #"9" then  state_69 lexbuf
  438.  else backtrack lexbuf
  439.  end)
  440. and state_63 lexbuf = (
  441.  let val currChar = getNextChar lexbuf in
  442.  case currChar of
  443.     #"`" => action_4 lexbuf
  444.  |  _ => backtrack lexbuf
  445.  end)
  446. and state_64 lexbuf = (
  447.  let val currChar = getNextChar lexbuf in
  448.  if currChar >= #"@" andalso currChar <= #"_" then  state_67 lexbuf
  449.  else backtrack lexbuf
  450.  end)
  451. and state_65 lexbuf = (
  452.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  453.  setLexLastAction lexbuf (magic action_10);
  454.  let val currChar = getNextChar lexbuf in
  455.  case currChar of
  456.     #"`" => action_4 lexbuf
  457.  |  _ => backtrack lexbuf
  458.  end)
  459. and state_67 lexbuf = (
  460.  let val currChar = getNextChar lexbuf in
  461.  case currChar of
  462.     #"`" => action_5 lexbuf
  463.  |  _ => backtrack lexbuf
  464.  end)
  465. and state_69 lexbuf = (
  466.  let val currChar = getNextChar lexbuf in
  467.  if currChar >= #"0" andalso currChar <= #"9" then  state_70 lexbuf
  468.  else backtrack lexbuf
  469.  end)
  470. and state_70 lexbuf = (
  471.  let val currChar = getNextChar lexbuf in
  472.  case currChar of
  473.     #"`" => action_6 lexbuf
  474.  |  _ => backtrack lexbuf
  475.  end)
  476. and state_76 lexbuf = (
  477.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  478.  setLexLastAction lexbuf (magic action_3);
  479.  let val currChar = getNextChar lexbuf in
  480.  case currChar of
  481.     #"*" => action_0 lexbuf
  482.  |  _ => backtrack lexbuf
  483.  end)
  484. and state_77 lexbuf = (
  485.  setLexLastPos lexbuf (getLexCurrPos lexbuf);
  486.  setLexLastAction lexbuf (magic action_3);
  487.  let val currChar = getNextChar lexbuf in
  488.  case currChar of
  489.     #")" => action_1 lexbuf
  490.  |  _ => backtrack lexbuf
  491.  end)
  492. and main lexbuf =
  493.   (setLexStartPos lexbuf (getLexCurrPos lexbuf);
  494.    state_4 lexbuf)
  495.  
  496. and action lexbuf =
  497.   (setLexStartPos lexbuf (getLexCurrPos lexbuf);
  498.    state_3 lexbuf)
  499.  
  500. and string lexbuf =
  501.   (setLexStartPos lexbuf (getLexCurrPos lexbuf);
  502.    state_2 lexbuf)
  503.  
  504. and char lexbuf =
  505.   (setLexStartPos lexbuf (getLexCurrPos lexbuf);
  506.    state_1 lexbuf)
  507.  
  508. and comment lexbuf =
  509.   (setLexStartPos lexbuf (getLexCurrPos lexbuf);
  510.    state_0 lexbuf)
  511.  
  512. (* The following checks type consistency of actions *)
  513. val _ = fn _ => [action_50, action_49, action_48, action_47, action_46, action_45, action_44, action_43, action_42, action_41, action_40, action_39, action_38, action_37, action_36, action_35, action_34, action_33, action_32, action_31, action_30, action_29, action_28];
  514. val _ = fn _ => [action_27, action_26, action_25, action_24, action_23, action_22, action_21];
  515. val _ = fn _ => [action_20, action_19, action_18, action_17, action_16, action_15, action_14, action_13, action_12];
  516. val _ = fn _ => [action_11, action_10, action_9, action_8, action_7, action_6, action_5, action_4];
  517. val _ = fn _ => [action_3, action_2, action_1, action_0];
  518.  
  519. end
  520.